import orderApi from '@/static/js/enterpriseServer/order.js'
import CountDown from "@/components/countDown/countDown.vue";
export default {
	components: {
		CountDown
	},
	data() {
		return {
			navCurrent: 0, //一级导航序号
			navList: [
				{
					id: '',
					name: '全部',
					index: 0
				},
				{
					id: 0,
					name: '待付款',
					index: 1
				},
				{
					id: 1,
					name: '服务中',
					index: 2
				},
				{
					id: 2,
					name: '待确认',
					index: 3
				},
				{
					id: 4,
					name: '已完成',
					index: 4
				}
			],
			//数据列表
			orderData: [],
			//分页参数
			pageShow: false,
			page: 1,
			pageSize: 10,
			isRefreshing: false,
			listStatus: 'nomore',
			titleColor: '#FF9B21'
		}
	},
	onLoad(e) {
		this.navCurrent = e.index
	},
	onShow() {
		this.getList()
	},
	methods: {
		//获取列表数据
		async getList() {
			this.listStatus = 'loading'
			uni.showLoading({
				title: '加载中'
			})
			let obj;
			if (this.navCurrent == 0) {
				obj = {
					page: this.page,
					pagesize: this.pageSize
				}
			} else {
				obj = {
					page: this.page,
					pagesize: this.pageSize,
					status: this.navList[this.navCurrent].id
				}
			}
			const res = await orderApi.getOrderList(obj)
			if (res.code === 1) {
				let arr = []
				if (this.page == 1) {
					this.orderData = []
				}
				let newList = res.data.serviceorderlist
				if (newList.length >= this.pageSize) {
					this.listStatus = 'more'
				} else {
					this.listStatus = 'nomore'
				}
				let arr1 = arr.concat(newList)
				arr1.forEach(val => {
					let obj = {
						id: val.id,
						serviceinfo: val.serviceinfo,
						shopinfo: val.shopinfo,
						money: val.money,
						order_no: val.order_no,
						status: val.status,
						createtime: val.createtime
					}
					this.orderData.push(obj)
				})
				this.pageShow = true
				this.isRefreshing = false
				uni.hideLoading()
			}
		},

		//导航栏切换
		menuClick(e) {
			this.navCurrent = e.index
			this.getList()
		},

		//删除订单
		delOrder(val) {
			let id = val.id
			let that = this
			uni.showModal({
				title: '温馨提示',
				confirmText: '确认删除',
				confirmColor: "#0177FD",
				cancelColor: '#999',
				cancelText: '再想想',
				content: '确认删除此订单吗？',
				success: function (res) {
					if (res.confirm) {
						orderApi.delOrder({ order_id: id }).then(ots => {
							if (ots.code === 1) {
								that.$tools.msg('删除成功')
								that.getList()
							} else {
								that.$tools.msg(ots.msg)
							}
						})
					}
				}
			})
		},

		//跳转订单详情
		orderDetail(val) {
			let that = this
			if (val.status === 0) {
				uni.navigateTo({
					url: '/enterpriseServer/orderDetails/index?orderNo=' + val.order_no
				})
			} else if (val.status === 2) {
				uni.showModal({
					title: '温馨提示',
					confirmColor: '#0177FD',
					confirmText: '确认验收',
					cancelColor: '#999',
					cancelText: '再想想',
					content: '是否确认验收服务',
					success: function (ots) {
						if (ots.confirm) {
							orderApi.sureOrder({ order_id: val.id, status: 3 }).then(res => {
								if (res.code === 1) {
									that.$tools.msg('验收成功')
									that.getList()
								} else {
									that.$tools.msg(ots.msg)
								}
							})
						}
					}
				})
			} else {
				uni.navigateTo({
					url: '/enterpriseServer/orderDetails/index?orderNo=' + val.order_no
				})
			}
		},

		//跳转服务商详情
		goService(val) {
			uni.navigateTo({
				url: '/enterpriseServer/merchantInfo/index?id=' + val.id
			})
		},

		//跳转订单详情
		goShopInfo(val) {
			uni.navigateTo({
				url: '/enterpriseServer/orderDetails/index?orderNo=' + val.order_no
			})
		},

		//下拉刷新
		refresherrefresh() {
			this.isRefreshing = true;
			this.page = 1
			this.getList()
		},

		//上拉加载
		loadMore() {
			if (this.listStatus == 'more') {
				this.page += 1
				this.getList()
			}
		}
	}
}